package org.shopen.ai.puremvc.model.algo
{
	import mx.collections.ArrayCollection;
	
	import org.puremvc.as3.patterns.proxy.Proxy;
	import org.shopen.ai.puremvc.model.algo.bfs.BreadthFirstSearchAlgo;
	import org.shopen.ai.puremvc.model.algo.dls.DepthLimitedSearchAlgo;
	import org.shopen.ai.puremvc.model.utils.ICompleteDelegate;

	public class AlgoProxy extends Proxy
	{
		public static const NAME : String = "AlgoProxy";
		
		public static const ALGORITHMS_LOADED : String = NAME + ".ALGORITHMS_LOADED";
		
		protected var algorithms : ArrayCollection = null;
		
		public function get isLoaded() : Boolean
		{
			var result : Boolean = algorithms != null;
			return result;
		}
		
		public function AlgoProxy()
		{
			super(AlgoProxy.NAME);
		}
		
		override public function getProxyName():String
		{
			return AlgoProxy.NAME;
		}
		
		public function getAlgorithms() : ArrayCollection
		{
			return algorithms;
		}
		
		public function loadAlgorithms(delegete : ICompleteDelegate, type : String = null) : void
		{
			if (!isLoaded)
			{
				initAlgorithms();
			}
			sendNotification(AlgoProxy.ALGORITHMS_LOADED, getAlgorithms(), type);
			delegete.dispatchComplete();
		}
		
		protected function initAlgorithms() : void
		{
			algorithms = new ArrayCollection();
			algorithms.addItem(new BreadthFirstSearchAlgo());
			// TODO: do smth with limit...
			algorithms.addItem(new DepthLimitedSearchAlgo(10));
		}
	}
}